#pragma once

#include <list>
#include <string>
#include "ActionNode.h"
#include "PPR.h"
#include <fstream>
#include <sstream>
#include <iostream>
#include <hash_map>

using namespace std;
using namespace stdext;


struct StarCraftRow
{
	int time;
	string observation;
	string action;
	vector<string> landmarks;
	vector<string> joinStates;
};

struct PPRObservationAction
{
	string observation;
	string action;
	string state;
};

struct ActHistJoin
{
	string action;
	string join;
	list<string> history;
};

class BuilderCSV
{
private:
	//list<PPRObservationAction> BuilderCSV::ConvertDataToPairs(string inputFile, string actionCol, vector<string> actions, string observationCol, vector<string> observations, string stateCol, vector<string> states);
	//list<PPRObservationAction> BuilderCSV::ConvertDataToPairs(list<string> inputRows, string actionCol, vector<string> actions, string observationCol, 
	//															vector<string> observations, string stateCol, vector<string> states, vector<string> joinStates);
	list<PPRObservationAction> BuilderCSV::ConvertDataToPairs(list<string> inputRows, string actionCol, vector<string> actions, string observationCol, 
																vector<string> observations, vector<string> joinStates);
	hash_map<string, PPR> BuilderCSV::PairsToTrees(hash_map<string, PPR> branches, list<PPRObservationAction> pairs, vector<string> observations, int treeLength);
	hash_map<string, PPR> BuilderCSV::MergeBranchInWithTrees(hash_map<string, PPR> branches, PPR branch);

	bool BuilderCSV::Is_number(string s);

	list<ActHistJoin> BuilderCSV::ParseHistoryRows(list<string> rows, int actionIndex, int historyindex, int joinIndex, vector<string> actions);
	PPR BuilderCSV::HistoryToBranch(ActHistJoin history, vector<string> actions, vector<string> observations);


public:
	BuilderCSV(void);
	hash_map<string, PPR> BuilderCSV::BuildFromCSV(hash_map<string, PPR> branches, string inputFile, string actionCol, vector<string> actions, 
													string observationCol, vector<string> observations, string stateCol, int treeLength, 
													vector<string> states, vector<string> joinStates);	
	hash_map<string, PPR> BuilderCSV::BuildFromCSV(hash_map<string, PPR> branches, list<string> inputRows, string actionCol, vector<string> actions, 
													string observationCol, vector<string> observations, string stateCol, int treeLength, 
													vector<string> states, vector<string> joinStates);
	hash_map<string, PPR> BuilderCSV::BuildFromCSVHistories(hash_map<string, PPR> branches, string inputFile, string ActionCol, vector<string> actions,
													vector<string> observations, string joinState, string historyCol);

	hash_map<string, PPR> BuilderCSV::BuildFromStarCraftUnitHistory(hash_map<string, PPR> branches, string inputFile, string ActionCol, vector<string> actions,
													string observationCol, vector<string> observations, vector<string> joinStates, vector<string> landmarkCols, 
													string timeCol, int timeStepDuration, int maxTreeLength);

	void BuilderCSV::TreesToPolicyFiles(hash_map<string, PPR> trees, string outputDirectory, string policyPrefix);
};

